package com.atguigu.tingshu;

import com.atguigu.tingshu.common.constant.RedisConstant;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

@Slf4j
@SpringBootApplication//(scanBasePackages = "com.atguigu.tingshu")
@EnableDiscoveryClient
@EnableFeignClients
@EnableCaching //开启springCache缓存
public class ServiceAlbumApplication {

    public static void main(String[] args) {
        SpringApplication.run(ServiceAlbumApplication.class, args);
    }

    @Autowired
    private RedissonClient redissonClient;


    /**
     * 构造方法执行后（对象实例化）
     * 启动类执行完毕后，springboot启动后执行一次
     */
    @PostConstruct
    public void initBloomFilter() {
        log.info("[专辑服务]启动项目后初始化布隆过滤器");
        RBloomFilter<Long> bloomFilter = redissonClient.getBloomFilter(RedisConstant.ALBUM_BLOOM_FILTER);
        //参数1：数据规模（业务增长扩容） 参数2：误判率
        bloomFilter.tryInit(100000, 0.03);
    }
}
